package com.example;

/**
 * Created by IntelliJ IDEA.
 * User: Andrzej
 * Date: 28.04.11
 * Time: 09:01
 * To change this template use File | Settings | File Templates.
 */

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;

import android.app.Activity;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.*;

public class AddToList extends Activity
{
     private static final String tag = "AddToList";
                 private DataHelper dh;
     private Button OK;
     private Button CANCEL;
     private EditText TITLE;
     private EditText  WHERE;
     private EditText  FROM;
     private EditText  TO;
     private EditText  DESCRIPTION;


            public void onCreate(Bundle savedInstanceState)
			{
				super.onCreate(savedInstanceState);
				setContentView(R.layout.addtask);

                this.CANCEL=(Button)this.findViewById(R.id.cancel);
                this.OK=(Button)this.findViewById(R.id.ok);

                this.FROM=(EditText)this.findViewById(R.id.from);
                this.TO=(EditText)this.findViewById(R.id.to);

                 this.TITLE=(EditText)this.findViewById(R.id.task);
                 this.WHERE=(EditText)this.findViewById(R.id.taskwhere);

                this.DESCRIPTION=(EditText)this.findViewById(R.id.description);



                this.CANCEL.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                         Intent in = getIntent();
                        setResult(RESULT_CANCELED,in);
                        finish();
                                }
                         });

                this.OK.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                        Task t=collectdata();

                            Intent in = getIntent();
                            in.putExtra("result",t);

                            setResult(RESULT_OK,in);
                            finish();




                                }
                         });



            }



            private Task collectdata()
            {
               String from= FROM.getText().toString();
               String to= TO.getText().toString();
               String where= WHERE.getText().toString();
               String title= TITLE.getText().toString();
               //String = DESCRIPTION.getText().toString();
               String data= (String) getIntent().getExtras().get("date");
               String description= DESCRIPTION.getText().toString();
               this.dh = new DataHelper(this);
               this.dh.insert(data, title, where, description, from, to);
               Task temp=new Task(data,title,where,from,to,description);
               return temp;

                      //
            }

}
